#region Copyright
/// <copyright>
/// Copyright (c) 2007 Ilia Shramko.
/// Released under the terms of the GNU General Public License.
/// </copyright>
#endregion

using System;
using System.Collections.Generic;
using System.Text;

namespace Osh.Teletext
{
	/// <summary>
	/// Packets X/27 with designation codes in the range 0000 to 0011 define editorially linked pages.
	/// </summary>
	public class PacketX270 : NonDisplayablePacket
	{
		public const int MaxNumberOfLinks = 6;
		private ushort _crc;
		private PageAddress[] _links;

		public PacketX270(int magazine, int packet, byte[] data, int position)
			: base(magazine, packet, TeletextDecoder.DecodeDesignationCode(data, position))
		{
			position++; // skip designation code
			_links = new PageAddress[MaxNumberOfLinks];
			for(int i = 0; i < MaxNumberOfLinks; i++)
			{
				PageAddress link = TeletextDecoder.DecodePageAddress(data, position + i * 6);
				link.Magazine = TeletextDecoder.Complement((byte)magazine, (byte)link.Magazine) & 7;

				_links[i] = link;
			}
			_crc = (ushort)((data[38] << 8) | data[39]);
		}

		public PageAddress[] Links
		{
			get { return _links; }
		}

		public ushort Crc
		{
			get { return _crc; }
		}
	}
}
